<template>
  <div class="m-geo">
    <div class="position">
      <i class="el-icon-location" />
      {{ $store.state.curPosition.name }}
      <router-link class="changeCity" :to="{ name: 'changeCity' }"
        >切换城市</router-link
      >
      [
      <a href="#" v-for="(item, index) in nearCity" :key="index">
        {{ item }}
      </a>
      ]
    </div>
    <div class="m-user" v-if="!$store.state.userName">
      <router-link class="login" :to="{ name: 'login' }">立即登录</router-link>
      <router-link class="register" :to="{ name: 'register' }"
        >注册</router-link
      >
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      position: this.$store.state.curPosition,
      userName: "",
      nearCity: ["沙坪坝", "渝北区", "垫江县"],
    };
  },
  watch: {
    "$store.state.position": function () {
      this.nearCity = this.$store.state.position.nearCity;
    },
    "position"(){
      this.position=this.$store.state.curPosition;
    }
  },
};
</script>
